/*
Web: http://www.jsForms.com
Copyright (C) 2008  Igor Demyanov (mailto:Igor.Demyanov@gmail.com)
    This program is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program.  If not, see <http://www.gnu.org/licenses/>.
*/
jsForms.Templates.UploadFileControl='<form method="post">'+
'<input name="form_param" type="hidden" />'+
'<input name="form_file" type="file" />'+
'<input type="submit" name="form_submit" value="Submit"/>'+
'</form>';

jsForms.Components["common.UploadFileControl"]={
	Init:function()
	{
		this.P.isInit = true;
		this.SetPostScript(this.P.PostScript)
			.SetPostParam(this.P.PostParam)
			.SetButtonText(this.P.ButtonText)
			.bind('submit',this,this.OnSubmitForm);
		return jsForms.Components.Component.Init.call(this);
	},
	SetButtonText:function(value){
		this.P.ButtonText = value;
		if (this.P.isInit !=true) 
		{
			return this;
		}
		if (value!=undefined){
			this.C.form_submit.val(value);
		}
		return this;
	},
	SetPostScript:function(value){
		this.P.PostScript = value;
		if (this.P.isInit !=true) 
		{
			return this;
		}
		if (value!=undefined){
			this.attr('action',value);
		}
		return this;
	},
	SetPostParam:function(value){
		this.P.PostParam = value;
		if (this.P.isInit !=true) 
		{
			return this;
		}
		if (value != undefined){
			this.C.form_param.val(value);
		}
		return this;
	},
	OnSubmitForm:function(e){
		return AIM.submit(this, {
			'onStart' : function(){
				e.data._ExecEvent('onStartUpload',e.data);
			},
			'onComplete' : function(result){
				e.data._ExecEvent('onComplete',e.data,result);
			}
		});
	}
};

jsForms.CreateCompileInfoByObject(
{
	Name: 'common.UploadFileControl',
	Properties: {
		PostScript: {
			Type: 'String',
			Access: 'SET'
		},
		PostParam:{
			Type: 'String',
			Access: 'SET'
		},
		ButtonText:{
			Type: 'String',
			Access: 'SET'
		}
	},
	Events: {
		onStartUpload:{},
		onComplete:{}
	}
});
